<?php

namespace App\Services\Warehouse\Model;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Tymon\JWTAuth\Contracts\JWTSubject;

class ERPUser extends Authenticatable implements JWTSubject
{
    protected $connection = 'kny';

    protected $table = 'users';

    protected $primaryKey = 'uid';

    protected $appends = ['mobile','avatar'];

    protected $visible = ['uid', 'name', 'mobile','avatar'];

    public function getMobileAttribute()
    {
        return $this->userDetail? $this->userDetail->tel: '';
    }

    public function getAvatarAttribute()
    {
        return $this->userDetail? $this->userDetail->avatar: 'https://kny-sxy.oss-accelerate.aliyuncs.com/designer/cartoon_avatar/21.png';
    }

    public function getJWTIdentifier()
    {
        return $this->getKey();
    }

    /**
     * 写入到jwt中的数据
     * @return array
     */
    public function getJWTCustomClaims()
    {
        return [];
    }

    public function userDetail()
    {
        return $this->hasOne(ERPUserDetail::class, 'uid', 'uid');
    }
}
